const CompanyInfo = require("../model/companyInfo");
const { validationResult, checkSchema } = require("express-validator");

module.exports = {
  // 获取公司信息
  getCompanyInfo: async (req, res) => {
    try {
      const companyInfo = await CompanyInfo.findOne({
        where: {
          company_id: 1,
        },
      });
      if (!companyInfo) {
        return res.json({ code: -1, message: "未找到公司信息" });
      }
      res.json({ code: 1, message: "获取成功", data: companyInfo });
    } catch (error) {
      console.error(error);
      res.status(500).json({ error: "服务器错误" });
    }
  },
  // 更新公司信息
  updateCompanyInfo: async (req, res) => {
    const { title, desc, phone, email, address, wechat_code, wechat_wa_code } = req.body;
    try {
      const companyInfo = await CompanyInfo.update(
        {
          title,
          description: desc,
          phone,
          email,
          address,
          wechat_code,
          wechat_wa_code,
        },
        { where: { company_id: 1 } }
      );
      if (companyInfo[0] === 0) {
        return res.json({ code: -1, message: "未找到公司信息" });
      }
      res.json({ code: 1, message: "更新成功" });
    } catch (error) {
      console.error(error);
      res.status(500).json({ error: "服务器错误" });
    }
  },
};
